import React, {Component} from 'react'
import {ListComponent} from '../../components'
import {ListBox} from '../../components'
import { Form, Modal, Button } from 'antd';
// 产品编码选择弹出框
export default class ProductModalTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            rowObj: {},
            isAdd: true
        }
        this.selectRowObj = {};
        this.rowOperation = [
            {
                handleName: 'rowClick',
                showName: '行单击选择事件'
            }
        ];
        this.headerOperation = [];

       //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏（用于列配置显示隐藏）, foreverHidden: true 列永久隐藏
        this.tableColumn = {
            data: [
                {
                    showName: '产品代码',
                    columnName: 'productCode',
                    columnWidth: 130
                },{
                    showName: '中文描述',
                    columnName: 'productDescZh'
                },{
                    showName: '英文描述',
                    columnName: 'productDescEn'
                }
            ]
        };

        this.searchComponentData = [
        ];
    }

    rowHandles = (strHandles, rowObj) => {
        if(strHandles == 'rowClick'){
            this.rowClickHandle(rowObj);
        }
    }

    rowClickHandle = (rowObj) => {    
        console.log('点击选中====',rowObj);    
        this.selectRowObj = rowObj[0].data;        
    }
    refreshHandle = () => {
        this.refs.listComponent.refreshHandle();
    }
    showModal = () => {
        this.setState({
            visible: true
        })
        this.selectRowObj = {};
    }
    handleOk = () => {
        this.setState({
            visible: false
        })
        this.props.getTableData(this.selectRowObj);
    }
    handleCancel = () => {
        this.setState({
            visible: false
        })
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <Modal
                    style={{top: '20px',maxHeight:'500px'}}
                    visible={this.state.visible}
                    title="产品编码选择"
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    width={'1250px'}
                    footer={[
                        <Button key="back" onClick={this.handleCancel}>取消</Button>,
                        <Button key="submit" type="primary" onClick={this.handleOk}>
                        确定
                        </Button>,
                    ]}
                    maskClosable={false}
            >
                <ListBox
                    url = '/base/product/list'
                    tableColumnData = {this.tableColumn}
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    ref = "listComponent"
                    searchComponentData={this.searchComponentData}
                    headerOperation = {this.headerOperation}
                    subtractHeight = '37'
                    subtractWidth ='145'
                    isRowSingle = "true"
                />
            </Modal>
        )
    }
}
